<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once APPPATH.'libraries/facebook/facebook.php';
class Admin extends CI_Controller {
  var $user_id;
  public function __construct(){
    parent::__construct();
    if(!is_fb_admin()) {
      redirect('tab/index');
    }
    global $facebook;
    $user_id = $facebook->getUser();
    // $this->output->enable_profiler(TRUE);
    $this->load->model('Users_model');
  }

	public function index($page = 1)
	{
	  define('ADMIN_AVATARS_PER_PAGE', 14);
	  $avatars = $this->Users_model->get_admin_avatars(ADMIN_AVATARS_PER_PAGE, ($page-1) * ADMIN_AVATARS_PER_PAGE);
    $total_avatars = $this->Users_model->total_avatars();


	  //$avatars = $this->Users_model->get_all_entries();
	  $fields = array('first_name', 'last_name', 'email', 'filename', 'status', 'timestamp');

    $this->load->view('header');
    $this->load->view('admin_index', array('avatars' => $avatars, 'fields' => $fields, 'pager_html' => _theme_pager('admin/index', $page, $total_avatars, ADMIN_AVATARS_PER_PAGE)));
    $this->load->view('footer');
  }

  function change_status($aid, $status) {
    $avatars = $this->Users_model->update_entry($aid, array('status' => $status));
  }

}